home *** CD-ROM | disk | FTP | other *** search
-
-
-
- RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp((((3333CCCC++++++++)))) RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp((((3333CCCC++++++++))))
-
-
-
- NNNNaaaammmmeeee
- RWDiskPageHeap - Rogue Wave library class
-
- SSSSyyyynnnnooooppppssssiiiissss
- #include <rw/diskpage.h>
-
-
-
- unsigned nbufs;
- unsigned pagesize;
- RWDiskPageHeap heap("filename", nbufs, pagesize) ;
-
-
-
-
- DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
- Class RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp is a specializing type of buffered page heap. It
- swaps its pages to disk as necessary.
-
- PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
- None
-
- EEEExxxxaaaammmmpppplllleeee
- In this example, 100 nodes of a linked list are created and strung
- together. The list is then walked, confirming that it contains 100
- nodes. Each node is a single page. The "pointer" to the next node is
- actually the handle for the next page.
-
- #include <rw/diskpage.h>
-
-
-
- #include <rw/rstream.h>
- struct Node {
- int key;
- RWHandle next;
- };
- RWHandle head = 0;
- const int N = 100; // Exercise 100 Nodes
- main() {
- // Construct a disk-based page heap with page size equal
- // to the size of Node and with 10 buffers:
- RWDiskPageHeap heap(0, 10, sizeof(Node));
- // Build the linked list:
- for (int i=0; i<N; i++){
- RWHandle h = heap.allocate();
- Node* newNode = (Node*)heap.lock(h);
- newNode->key = i;
- newNode->next = head;
- head = h;
- heap.dirty(h);
- heap.unlock(h);
-
-
-
- PPPPaaaaggggeeee 1111
-
-
-
-
-
-
- RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp((((3333CCCC++++++++)))) RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp((((3333CCCC++++++++))))
-
-
-
- }
- // Now walk the list:
- unsigned count = 0;
- RWHandle nodeHandle = head;
- while(nodeHandle){
- Node* node = (Node*)heap.lock(nodeHandle);
- RWHandle nextHandle = node->next;
- heap.unlock(nodeHandle);
- heap.deallocate(nodeHandle);
- nodeHandle = nextHandle;
- count++;
- }
- cout << "List with " << count << " nodes walked.0;
- return 0;
- }
-
-
- PPPPrrrrooooggggrrrraaaammmm oooouuuuttttppppuuuutttt::::
-
- List with 100 nodes walked.
-
-
-
- PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrr
- RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp(const char* filename = 0,
- unsigned nbufs = 10,
- unsigned pgsize = 512);
-
-
- Constructs a new disk-based page heap. The heap will use a file with
- filename ffffiiiilllleeeennnnaaaammmmeeee, otherwise it will negotiate with the operating system
- for a temporary filename. The number of buffers, each the size of the
- page size, will be nnnnbbbbuuuuffffssss. No more than this many pages can be locked at
- any one time. The size of each page is given by ppppggggssssiiiizzzzeeee. To see whether
- a valid RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp has been constructed, call member function
- iiiissssVVVVaaaalllliiiidddd(((()))).
-
- PPPPuuuubbbblllliiiicccc DDDDeeeessssttttrrrruuuuccccttttoooorrrr
- virtual
- ~RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp();
-
-
- Returns any resources used by the disk page heap back to the operating
- system. All pages should have been deallocated before the destructor is
- called.
-
- PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
- virtual RWHandle
- aaaallllllllooooccccaaaatttteeee();
-
-
- Redefined from class RRRRWWWWVVVViiiirrrrttttuuuuaaaallllPPPPaaaaggggeeeeHHHHeeeeaaaapppp. Allocates a page off the disk
-
-
-
- PPPPaaaaggggeeee 2222
-
-
-
-
-
-
- RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp((((3333CCCC++++++++)))) RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp((((3333CCCC++++++++))))
-
-
-
- page heap and returns a handle for it. If there is no more space (for
- example, the disk is full) then returns zero.
-
- virtual void
- ddddeeeeaaaallllllllooooccccaaaatttteeee(RWHandle h);
-
-
- Redefined from class RRRRWWWWBBBBuuuuffffffffeeeerrrreeeeddddPPPPaaaaggggeeeeHHHHeeeeaaaapppp. Deallocate the page associated
- with handle hhhh. It is not an error to deallocate a zero handle.
-
- virtual void
- ddddiiiirrrrttttyyyy(RWHandle h);
-
-
- Inherited from RRRRWWWWBBBBuuuuffffffffeeeerrrreeeeddddPPPPaaaaggggeeeeHHHHeeeeaaaapppp.
-
- RWBoolean
- iiiissssVVVVaaaalllliiiidddd() const;
-
-
- Returns TTTTRRRRUUUUEEEE if this is a valid RRRRWWWWDDDDiiiisssskkkkPPPPaaaaggggeeeeHHHHeeeeaaaapppp.
-
- virtual void*
- lllloooocccckkkk(RWHandle h);
-
-
- Inherited from RRRRWWWWBBBBuuuuffffffffeeeerrrreeeeddddPPPPaaaaggggeeeeHHHHeeeeaaaapppp.
-
- virtual void
- uuuunnnnlllloooocccckkkk(RWHandle h);
-
-
- Inherited from RRRRWWWWBBBBuuuuffffffffeeeerrrreeeeddddPPPPaaaaggggeeeeHHHHeeeeaaaapppp.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- PPPPaaaaggggeeee 3333
-
-
-
-